<?php echo $documentForm->renderGlobalErrors()?>
<?php echo $debitMemoForm->renderGlobalErrors()?>
<?php echo $documentForm['document_iden']?>
<?php echo $documentForm['_csrf_token']?>
<?php echo $debitMemoForm['debit_iden']?>
<?php echo $debitMemoForm['customer_iden']?>
<?php echo $debitMemoForm['invoice_iden']?>
<?php echo $debitMemoForm['_csrf_token']?>
<table class="form">
  <tr>
    <th class="field"><?php echo $documentForm['owner_iden']->renderLabel()?></th>
    <td>
      <?php echo $documentForm['owner_iden']->renderError()?>
      <?php echo $documentForm['owner_iden']?>
    </td>
  </tr>
  <tr>
    <th class="field"><?php echo $documentForm['counter_code']->renderLabel()?></th>
    <td>
      <?php echo $documentForm['counter_code']->renderError()?>
      <?php echo $documentForm['counter_code']?>
    </td>
  </tr>
  <tr>
    <th class="field"><?php echo $debitMemoForm['debit_type']->renderLabel()?></th>
    <td>
      <?php echo $debitMemoForm['debit_type']?>
      <?php echo $debitMemoForm['debit_number']->renderError()?>
      <?php echo $debitMemoForm['debit_number']?>
    </td>
  </tr>
  <tr>
    <th class="field"><?php echo $documentForm['document_date']->renderLabel()?></th>
    <td>
      <?php echo $documentForm['document_date']->renderError()?>
      <?php echo $documentForm['document_date']?>
    </td>
  </tr>
  <tr>
    <th class="field"><?php echo $debitMemoForm['remarks']->renderLabel()?></th>
    <td>
      <?php echo $debitMemoForm['remarks']->renderError()?>
      <?php echo $debitMemoForm['remarks']?>
    </td>
  </tr>
  <tr>
    <th class="field">Invoice#</th>
    <td>
        <?php echo $invoice->getInvoiceNumber();?>
    </td>
  </tr>
  <tr>
    <th class="field"><?php echo $debitMemoForm['amount']->renderLabel()?></th>
    <td>
      <?php echo $debitMemoForm['amount']->renderError()?>
      <?php echo $debitMemoForm['amount']?>
    </td>
  </tr>
</table>



<script language="javascript">
  $(document).ready(function(){
    $('#debit_memo_debit_number').blur(function(){
      $.getJSON(
        'debitMemo/checkId',
        {
          "debit_iden":$('#debit_memo_debit_iden').val(),
          "debit_type":$('#debit_memo_debit_type').val(),
          "debit_number":$('#debit_memo_debit_number').val(),
        },
        function(data){
          if(data.count > 0){
            debit_id = $('#debit_memo_debit_type').val()+'-'+$('#debit_memo_debit_number').val();
            alert(debit_id+' already exists.');
          }
        }
      );
    });
  });
</script>